package com.nx.mr.wordcount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @Author: Qingwr
 * @Date: 2022/8/13 21:07
 * @Description shuffle-分区
 */
public class MyPartitioner extends Partitioner<Text, LongWritable> {

    @Override
    public int getPartition(Text text, LongWritable longWritable, int numPartitions) {
        //需求：根据单词的长度进行判断，单词长度>=5的在一个文件中，<5的在一个文件中
        if (text.toString().length() >= 5) {
            return 0;
        } else {
            return 1;
        }
    }
}
